const { chromium } = require("playwright"); // 或使用 'firefox' 或 'webkit'
require("dotenv").config();
(async () => {
  // 启动浏览器
  const browser = await chromium.launch({
    headless: false,
    timeout: 300000,
    slowMo: 500,
    args: ["--no-sandbox", "--disable-setuid-sandbox", "--start-maximized"],
  }); // headless: false 以便你能看到操作
  const context = await browser.newContext();
  const page = await context.newPage();
  const username = process.env.username;
  const password = process.env.password;
  // 前往购物车页面
  await page.goto(
    "https://www.isseymiyake.com/account/login?redirect_to=myaccount"
  );

  // 提交订单

  await page.fill('input[name="login_email"]', username);
  await page.fill('input[name="login_password"]', password);
  // 使用 id 定位并点击 login_button 按钮
  await page.click("#login_button");

  // 填写结算信息
  //   await page.fill('input[name="address"]', "yourAddress");
  //   await page.fill('input[name="payment"]', "yourPaymentMethod");
  //   await page.click("button.place-order");
  //
  await page.goto("https://www.isseymiyake.com/cart");
  await page.click("#checkout");
  // 确认订单已提交
  https: await page.waitForSelector("div.order-confirmation");
  console.log("Order placed successfully!");

  // 关闭浏览器
  await browser.close();
})();
